package com.zr.daoImpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.zr.dao.DeleteteasDaoljc;
import com.zr.model.User;
import com.zr.util.JDBCUtil;

public class DeleteteasDaoImplljc implements DeleteteasDaoljc{

	@Override
	public boolean deleteTeaByTid(int tid,Connection con) {
		boolean flag = false;
		StringBuffer sql = new StringBuffer("");
		sql.append(" DELETE FROM teacher");
		sql.append(" WHERE teacher.tid=?");
		try {
			PreparedStatement pst = con.prepareStatement(sql.toString());
			pst.setInt(1, tid);
			int i = pst.executeUpdate();
			if(i>0){
				flag=true;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return flag;
	}

	@Override
	public boolean deleteUserByUid(int uid, Connection con) {
		boolean flag = false;
		StringBuffer sql = new StringBuffer("");
		sql.append(" DELETE FROM user");
		sql.append(" WHERE user.uid=?");
		try {
			PreparedStatement pst = con.prepareStatement(sql.toString());
			pst.setInt(1, uid);
			int i = pst.executeUpdate();
			if(i>0){
				flag=true;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return flag;
	}

	@Override
	public User findUidByTid(int tid) {
		User u = new User();
		StringBuffer sql = new StringBuffer();
		sql.append(" SELECT uid FROM user");
		sql.append(" where tid=?");
		Connection con = JDBCUtil.getConnection();
		try {
			PreparedStatement pst = con.prepareStatement(sql.toString());
			pst.setInt(1, tid);
			ResultSet rs = pst.executeQuery();
			while(rs.next()){
				u.setUid(rs.getInt("uid"));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return u;
	}

}
